/**
 * Created by asus on 2017/5/7.
 */
public class Complex {
    private double RealPart;
    private double ImagePart;

    public Complex(double m, double n) {
        this.RealPart = m;
        this.ImagePart = n;
    }

    // add
    public Complex add(Complex c) {
        return new Complex(RealPart + c.RealPart, ImagePart + c.ImagePart);
    }

    // minus
    public Complex minus(Complex c) {
        return new Complex(RealPart - c.RealPart, ImagePart- c.ImagePart);
    }

    // multiply
    public Complex multiply(Complex c) {
        return new Complex(RealPart * c.RealPart - ImagePart* c.ImagePart, RealPart * c.ImagePart + ImagePart * c.RealPart);
    }

    // divide
    public Complex divide(Complex c) {
        double d = Math.sqrt(c.RealPart* c.RealPart) + Math.sqrt(c.ImagePart * c.ImagePart);
        return new Complex((RealPart * c.RealPart + ImagePart* c.ImagePart) / d, Math.round((RealPart * c.ImagePart - ImagePart * c.RealPart) / d));
    }

    public String toString() {
        String rtr_str = "";
        if (ImagePart> 0)
            rtr_str = "(" + RealPart+ "+" + ImagePart+ "i" + ")";
        if (ImagePart== 0)
            rtr_str = "(" + RealPart+ ")";
        if (ImagePart< 0)
            rtr_str = "(" + RealPart +ImagePart + "i" + ")";
        return rtr_str;
    }
}



